﻿
//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef PROPERTYCOMBOXGROUPS_H
#define PROPERTYCOMBOXGROUPS_H
#pragma once

#include <memory>
#include <vector>
#include <QComboBox>

namespace Sample
{
    class CComponentTypeGroup;
    class CComponentTypeItem;
    class CComponentTypeWidget;
    class CPropertyWidget;

    class QComboxGroups : public QWidget
    {
        Q_OBJECT
    public:
        QComboxGroups(QWidget *parent);
        virtual ~QComboxGroups();

        // 设置当前项
        bool setCurrentItem( int groupIndex,int indexInGroup );
     
        // 添加一个组（组索引必须是有效组索引，否则无法添加）
        bool AddItemsGroup(int groupIndex, CComponentTypeGroup * pComponentTypeGroup);
        // 必须已经有组了才能添加
        bool AddItem(int groupIndex, int indexInGroup, CComponentTypeItem * pComponentTypeItem);

        // 移除指定组内的一个项 /*当移除完组内最后一个条目以后 就移除组分隔条*/
        bool RemoveItem(int groupIndex, int indexInGroup);
        // 移除一个组
        bool RemoveItemsGroup(int groupIndex);
        // 移除所有组
        bool RemoveAllItemsGroup();

        // 设置默认显示
        void SetDefaultComboBox(const QString& defText, const QIcon &icon);

        //设置显示状态
        void SetEnableComponentTypeChangeComboBox(bool isEnable);

    protected slots:
        void OnComboBoxChanged();

    signals:
        void SelectChangedComponentType(const CComponentTypeItem *pComponentTypeItem); 

    private:
        int GetComboBoxIndex(int groupIndex,int indexInGroup);
        CComponentTypeItem * GetTypeItemByIndex(int idxcombobox);
        
    private:
        typedef std::vector<CComponentTypeGroup*>  TypeGroupVec;
        typedef std::map<CComponentTypeGroup *, std::vector<CComponentTypeItem*>>  TypeGroupMap;

        TypeGroupVec                m_ComponentTypeGroups;
        TypeGroupMap                m_ComponentTypeItems;
        std::unique_ptr<QComboBox>  m_upComboBox;
    };

}//namespace Sample

#endif // PROPERTYCOMBOXGROUPS_H

